local wengang = fk.CreateSkill{
    name = "ym2__wengang",
}
local U = require "packages/utility/utility"
Fk:loadTranslationTable{
    ["ym2__wengang"] = "紊纲",
    [":ym2__wengang"] = "一个回合结束时，若你此回合失去过装备区的牌，你可以令当前回合角色视为对你选择的另一名角色使用冰【杀】，然后你获得等量张此回合进入弃牌堆的牌。",
    ["#ym2__wengang-tos"] = "是否发动 紊纲，令 %dest 视为对你指定的角色使用一张冰【杀】",
    ["#ym2__wengang-give"] = "紊纲：获得本回合进入弃牌堆的%arg张牌",

    ["$ym2__wengang1"] = "与我作对的，通通难逃一死！",
    ["$ym2__wengang2"] = "你以为我不知道你干的好事？",
}
wengang:addEffect(fk.TurnEnd,{
    anim_type = "control",
    can_trigger = function (self, event, target, player, data)
        local room = player.room
        if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
            if move.from == player and move.to ~= player then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerEquip then
                        return true
                    end
                end
            end
        end
        end, Player.HistoryTurn) == 0 then return end
        return player:hasSkill(wengang.name)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local card = Fk:cloneCard("ice__slash")
        card.skillName = wengang.name
        local targets = table.filter(room:getAlivePlayers(),function (tp)
            return not room.current:prohibitUse(card) and room.current:canUseTo(card,tp,{bypass_distances = true,bypass_times = true})
        end)
        if #targets > 0 then
            local tos = room:askToChoosePlayers(player,{
                max_num = 1,
                min_num = 1,
                targets = targets,
                skill_name = wengang.name,
                prompt = "#ym2__wengang-tos::"..room.current.id
            })
            if #tos > 0 then
                event:setCostData(self,tos)
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local tos = event:getCostData(self)
        local n = 0
        room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
            if move.from == player and move.to ~= player then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerEquip then
                        n = n + 1
                    end
                end
            end
        end
        end, Player.HistoryTurn)
        room:useVirtualCard("ice__slash", nil, room.current, tos, wengang.name)
        local ids = {}
        room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
            for _, move in ipairs(e.data) do
            if move.toArea == Card.DiscardPile then
                for _, info in ipairs(move.moveInfo) do
                table.insertIfNeed(ids, info.cardId)
                end
            end
            end
        end, Player.HistoryTurn)
        ids = table.filter(ids, function (id)
            return table.contains(room.discard_pile, id)
        end)
        if #ids == 0 then return end
        if #ids > n then
            ids = room:askToChooseCards(player, {
                target = player,
                min = n,
                max = n,
                flag = { card_data = {{ "pile_discard", ids }} },
                skill_name = wengang.name,
                prompt = "#ym2__wengang-give:::"..U.ConvertNumber(n),
            })
        end
        room:moveCards({
            ids = ids,
            to = player,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonJustMove,
            proposer = player,
            skillName = wengang.name,
            moveVisible = true,
        })
    end,
})
return wengang